export interface Store {
  name: string,
  age: number,
  sex?: boolean
}

export default {
  namespaced: true,
  modules: {
    account: {
      state: { // 仓库
        name: 'tom',
        age: 18,
        sex: true
      },
      getters: { // 过滤
        getAge(state: Store): string {
          if (state.age >= 18) return '成年';
          return '未成年';
        }
      },
      mutations: { // 修改
        setAge(state: Store, age: number) {
          console.log('moduleA.setAge');
          state.age = age
        }
      },
      actions: { // 异步
        setAgeActions(context: any, age: number) {
          setTimeout(() => { // 模拟异步
            context.commit('setAge', age)
          }, 1000);
        }
      }
    }
  }
}
